<?php
$data = $orm->get('pb_plugin', 't.folder', 'ASC', NULL, NULL, NULL)->d;
?>
<style>
.pure_table_extra { margin-top: 0; }
.pure_table_extra th { height: 30px; line-height: 30px; }
object { margin: 0; }
</style>
<div id="spanButtonPlaceHolder"></div>
<table class="pure-table pure_table_extra" cellpadding=0 cellspacing=0>
  <thead>
    <th class="ui-widget-header ui-corner-left" style="width: 250px;">Plugin</th>
    <th class="ui-widget-header ui-corner-right" style="width: 40px;">&nbsp;</th>
  </thead>
  <tbody id="data_body"></tbody>
</table>

<script type="text/javascript">
  var __data = JSON.parse('<?php echo addslashes(json_encode($data)); ?>');
  var __dir = '<?php echo $dir; ?>';
  var __file = '<?php echo $file; ?>';
  var __session_id = '<?php echo session_id(); ?>';
  
  $(function(){
    set_data();
    
    Upload.init(
      'spanButtonPlaceHolder', 
      'ext.php', 
      function(rslt, srv_err) {
        __data = __data.concat(rslt);
        Utils.sort_by_attr('folder', __data);
        set_data();
      }, 
      {
        file_types: '*.zip',
        file_types_description: __dir,
        post_params: {
          PHPSESSID: __session_id,
          action: __dir
        },
        debug: 0
      }
    );
  });
  
  
  
  function set_data() {
    $('#data_body').empty();
    for (var idx in __data) {
      var itm = __data[idx];
      $('#data_body').append(
          '<tr class="' + ((idx % 2 == 0) ? 'pure-table-even' : 'pure-table-odd') + '">' + 
            '<td>' + itm.folder + '</td>' +
            '<td><img style="cursor: pointer;" src="src/' + __dir + '/images/delete.png" onclick="delete_obj(' + itm.id + ', \'' + itm.folder + '\')"></img></td>' + 
          '</tr>');
    }
    if (__data.length == 0) {
      $('#data_body').append('<tr class="pure-table-even"><td colspan=2>None</td></tr>');
    }
  }
  
  function delete_obj(id, folder) {
    var req = {
      id: id,
      folder: folder
    };
    
    Ajax.request(
      'firewall.php?d=' + __dir + '&f=' + __file + '&m=delete_obj',
      'req=' + Utils.encodeURI(JSON.stringify(req)),
      function(rslt) {
        Utils.splice_by_id(rslt.id, __data);
        set_data();
      },
      { confirm: 1 }
    );
  }
</script>